package high.concurent.service.impl;

import high.concurent.service.MailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * 邮件发送
 */
@Service
@Slf4j
public class MailServiceImpl implements MailService {

    @Autowired(required = false)
    private JavaMailSender javaMailSender;

//    @Value(value = "${spring.mail.from}")
//    private String from;
    /**
     * 邮箱发送
     * @param to 收信人邮箱
     * @param subject   主题
     * @param content   内容
     */
    @Override
    public void sendMail(String to, String subject, String content) {

        // 创建邮箱消息对象
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();

        // 邮件发送人
        simpleMailMessage.setFrom("a645293829@163.com");

        // 邮件收件人
        simpleMailMessage.setTo(to);

        // 邮件主题
        simpleMailMessage.setSubject(subject);

        // 邮件内容
        simpleMailMessage.setText(content);

        // 发送邮件
        javaMailSender.send(simpleMailMessage);

        log.info("邮件发送成功:{}", simpleMailMessage.toString());

    }
}
